#include <math.h>
#include <stdlib.h>

void freichen_c (unsigned char *src, unsigned char *dst, int h, int w, int row_size) {
int result = 0;
int filtroX,filtroY;
unsigned char *pxl,*pxlaux;
unsigned char *grabar, *grabaraux;
int i,j;
float r = sqrt(2);
grabar = dst + row_size + 1 ;
pxl = src + row_size + 1;
grabaraux = grabar;
pxlaux = pxl;

    for(i = 0; i < h - 2; i++){
	pxl = pxlaux;
        grabar = grabaraux;
        for(j = 0; j < w - 2; j++){
		result = 0;     
		filtroX = -*(pxl-row_size-1)-r*(*(pxl-1))-*(pxl+row_size-1)+*(pxl-row_size+1)+r*(*(pxl+1))+*(pxl+row_size+1);
		filtroY = -*(pxl-row_size-1)-r*(*(pxl-row_size))-*(pxl-row_size+1)+*(pxl+row_size-1)+r*(*(pxl+row_size))+*(pxl+row_size+1);

		filtroX = (int) abs(filtroX);
		filtroY = (int) abs(filtroY);

		result  = (int) (filtroX + filtroY);

		if(result > 0xFF){
		    *grabar = (unsigned char) 0xFF;
		} else {
		    *grabar = (unsigned char)result;
		}
		pxl++;
		grabar++;
        }
 
	pxlaux = pxlaux + row_size;
	grabaraux = grabaraux + row_size;
    }
}


